import * as api from '../../api/common';

Page({
  data: {
    orderId: '',
    orderInfo: {}
  },
  onLoad: function (options) {
    this.setData({
      orderId: options.id
    })
    this.getInfo()
  },
  async getInfo() {
    try {
      const {
        data
      } = await api.orderInfo({
        id: this.data.orderId
      });
      const baseUrl = api.baseUrl + '/';
      
      if (data.items[0]) {
        data.ticketInfo = data.items[0];
        data.ticketInfo.img = baseUrl + data.ticketInfo.img
      }
      
      if (data.ticketInfo) {
        if (data.ticketInfo.start_date) {
          let arr = data.ticketInfo.start_date.split('-')
          data.ticketInfo.start_date_f = arr[0] + '年' + arr[1] + '月' + arr[2] + '日'
        }
        if (data.ticketInfo.end_date) {
          let arr = data.ticketInfo.end_date.split('-')
          data.ticketInfo.end_date_f = arr[0] + '年' + arr[1] + '月' + arr[2] + '日'
        }
        data.status = data.ticketInfo.order_status
        data.price = data.ticketInfo.price
      }
      this.setData({
        orderInfo: data
      })
    }  catch (error) {
      console.error('获取票据详情失败', error);
    }
  },
})